package com.zhiyou100.listening;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * @author yang
 */
public class SessionLiveListener   implements HttpSessionListener{

	@Override
	public void sessionCreated(HttpSessionEvent event) {
		   ServletContext application=event.getSession().getServletContext();
		   Integer onLineCount=(Integer)application.getAttribute("onLineCount");
		   onLineCount++;
		   application.setAttribute("onLineCount", onLineCount);
	}
	@Override
	public void sessionDestroyed(HttpSessionEvent event) {
		   ServletContext application=event.getSession().getServletContext();
		   Integer onLineCount=(Integer)application.getAttribute("onLineCount");
		   onLineCount--;
		   application.setAttribute("onLineCount", onLineCount);
	}

}
